package com.cnyz.service.impl;

import com.cnyz.base.PageResponse;
import com.cnyz.dto.ExamDto;
import com.cnyz.entity.Exam;
import com.cnyz.mapper.ExamMapper;
import com.cnyz.service.ExamService;
import com.cnyz.vo.ExamVo;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import io.swagger.models.auth.In;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ExamServiceImp implements ExamService {
    @Autowired
    private ExamMapper examMapper;

    @Override
    public int addExam(ExamDto examDto) {
        Exam exam = new Exam();
        BeanUtils.copyProperties(examDto, exam);
        return examMapper.insertExam(exam);
    }

    @Override
    public PageResponse<ExamVo>  getExamPage(Integer pageNum, Integer pageSize, String name) {
        PageHelper.startPage(pageNum, pageSize);
        List<ExamVo> examList = examMapper.getExamList(name);
        Page<ExamVo> page = (Page<ExamVo>) examList;
        return PageResponse.of(page, ExamVo.class);
    }

    @Override
    public void deleteExam(Long id) {
        examMapper.deleteExam(id);
    }

    @Override
    public void setPaperToExam(Long id, Long paperId) {
        examMapper.setPaperToExam(id, paperId);
    }
}
